import { createClient } from 'redis';

// 创建Redis客户端
const client = createClient({
  host: process.env.REDIS_HOST || 'localhost',
  port: parseInt(process.env.REDIS_PORT || '6379'),
  password: process.env.REDIS_PASSWORD || undefined,
});

// Redis错误处理
client.on('error', (err) => {
  console.error('Redis Client Error:', err);
});

// Redis连接成功
client.on('connect', () => {
  console.log('Connected to Redis server');
});

// 尝试连接到Redis，但不阻止应用启动
client.connect().catch((err) => {
  console.warn('Redis connection failed, continuing without Redis:', err.message);
});

export default client;